<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
</head>

<body>
    <script>
        // 第一道题
        // setTimeout(function() {
        //     console.log("1");
        // });//宏任务
        // setTimeout(function() {
        //     console.log("22");
        // });//宏任务
        // setTimeout(function() {
        //     console.log("33");
        // });//宏任务
        // new Promise(function(resolve) {
        //         console.log("2");//同步
        //         resolve();
        //     })
        //     .then(function() {
        //         console.log("3");//微任务
        //     })
        //     .then(function() {
        //         console.log("4");//微任务
        //     });
        // console.log("5");//同步

        // 第二道题
        console.log(1);
        setTimeout(function() {
            console.log(2);
            new Promise(function(resolve) {
                console.log(3);
                resolve();
            }).then(function() {
                console.log(4);
            });
        });

        new Promise(function(resolve) {
            console.log(5);
            resolve();
        }).then(function() {
            console.log(6);
        });

        setTimeout(function() {
            console.log(7);
            new Promise(function(resolve) {
                console.log(8);
                resolve();
            }).then(function() {
                console.log(9);
            });
        });
        console.log(10);
        // 1 5 10 6 2 3 4 7 8 9

        setTimeout(function() {
            console.log("setTimeout1");
            new Promise(function(resolve) {
                resolve();
            }).then(function() {
                new Promise(function(resolve) {
                    resolve();
                }).then(function() {
                    console.log("then4");
                });
                console.log("then2");
            });
        });

        new Promise(function(resolve) {
            console.log("promise1");
            resolve();
        }).then(function() {
            console.log("then1");
        });

        setTimeout(function() {
            console.log("setTimeout2");
        });

        console.log(2);

        new Promise(function(resolve) {
            resolve();
        }).then(function() {
            console.log("then3");
        });

        async function async1() {
            console.log("async1 start");
            await async2();
            console.log("async1 end");
        }

        async function async2() {
            console.log("async2");
        }

        console.log("script start");

        setTimeout(function() {
            console.log("setTimeout");
        }, 0);

        async1();

        new Promise(function(resolve) {
            console.log("promise1");
            resolve();
        }).then(function() {
            console.log("promise2");
        });

        console.log("script end");
    </script>
</body>

</html>